package ${basePackage}.web;
import ${basePackage}.core.Result;
import ${basePackage}.core.ResultGenerator;
import ${basePackage}.model.${modelNameUpperCamel};
import ${basePackage}.service.${modelNameUpperCamel}Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by ${author} on ${date}.
*/
@RestController
@RequestMapping("${baseRequestMapping}")
public class ${modelNameUpperCamel}Controller {
    @Resource
    private ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @PostMapping("/add")
    public Result add(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        if (${modelNameLowerCamel}.getId() != null) {
            if (${modelNameLowerCamel}Service.update${modelNameUpperCamel}(${modelNameLowerCamel}) > 0) {
                return ResultGenerator.genSuccessResult();
            }
        } else {
            if (${modelNameLowerCamel}Service.add${modelNameUpperCamel}(${modelNameLowerCamel}) > 0) {
                return ResultGenerator.genSuccessResult();
            }
        }
        return ResultGenerator.genFailResult("操作失败");
    }

    @PostMapping("/flag")
    public Result flag(@RequestParam Integer id, @RequestParam(defaultValue = "0") Integer flag) {
        if (${modelNameLowerCamel}Service.update${modelNameUpperCamel}Flag(id, flag) > 0) {
            return ResultGenerator.genSuccessResult();
        }
        return ResultGenerator.genFailResult("操作失败");
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
        List<${modelNameUpperCamel}> datas = ${modelNameLowerCamel}Service.get${modelNameUpperCamel}s(page, rows);
    Integer total = ${modelNameLowerCamel}Service.get${modelNameUpperCamel}sCount();
    return ResultGenerator.genSuccessGridResult(total, datas);
    }
}
